<template>
    <TablePro v-bind="tableConfig" />
</template>

<script setup>

import TablePro from '@/components/TablePro.vue';
import { getLogs } from '@/apis/event';
import { reactive } from 'vue';
import { eventList } from '@/config/index'
import { timestampToDate } from '@/util/common';

const tableConfig = reactive({
    // 传递方法
    apiData: getLogs,
    fields: { message_id: '消息ID', post_type: '事件类型', self_id: '机器人', message_type: '消息类型', sub_type: '子类型', group_id: '群号', message: '消息内容', raw_message: '原始消息', font: '字体', sender: '发送者', user_id: '用户ID', target_id: '接收者QQ号', temp_source: '临时会话来源', anonymous: '匿名信息', file: '文件信息', comment: '验证信息', time: '时间' },
    showOverflowTooltip: ['message', 'raw_message'],
    custom: {
        sender: {
            type: 'popover'
        },
        anonymous: {
            type: 'popover'
        },
        post_type: {
            label: (scope) => {
                return eventList['post_type']?.[scope.row.post_type] || '-';
            }
        },
        message_type: {
            label: (scope) => {
                return eventList['message_type']?.[scope.row.message_type] || '-';
            }
        },
        sub_type: {
            label: (scope) => {
                return eventList['sub_type']?.[scope.row.sub_type] || '-';
            }
        },
        temp_source: {
            label: (scope) => {
                return eventList['temp_source']?.[scope.row.temp_source] || '-';
            }
        },
        time: {
            label: (scope) => {
                return timestampToDate(scope.row.time);
            },
        },
    },
    searchFields: [
        {
            key: 'post_type',
            label: '事件类型',
            type: 'select',
            placeholder: '请选择事件',
            options: Object.entries(eventList['post_type']).map(([label, value]) => ({ label:value, value:label })),
        },
        {
            key: 'message_type',
            label: '消息类型',
            type: 'select',
            placeholder: '请选择消息类型',
            options: Object.entries(eventList['message_type']).map(([label, value]) => ({ label:value, value:label })),
        },
        {
            key: 'sub_type',
            label: '子类型',
            type: 'select',
            placeholder: '请选择子类型',
            options: Object.entries(eventList['sub_type']).map(([label, value]) => ({ label:value, value:label })),
        },
        {
            key: 'temp_source',
            label: '临时会话来源',
            type: 'select',
            placeholder: '请选择来源',
            options: Object.entries(eventList['temp_source']).map(([label, value]) => ({ label:value, value:label })),
        },
    ],
    num:10
})
</script>